<template>
  <div class="wrap business-common">
    <b-textarea label="配置说明:" default="" id="configMessage" ref="fields1" :cssStyle="cssStyle"></b-textarea>
    <b-file
      label="附件:"
      :default="[]"
      :id="'attach'"
      ref="fields2"
      @showBigImg="showBigImg"
      :btnStyle="{type: 'primary', text: '上传', size: 'mini', icon: false}">
    </b-file>
    <b-input label="联系人:" default="" id="linker" ref="fields3"></b-input>
    <b-input label="联系方式:" default="" id="linkerphone" ref="fields4"></b-input>
    <p class="prompt">建议您可以留下一个联系方式，方便后续我们可以更快捷的 联系到您，以便对问题进行确认</p>
    <div class="btn">
      <button type="button" class="el-button primary_btn" @click.stop="backHome">取消</button>
      <button type="button" class="el-button primary_btn el-button--primary" @click.stop="submit">提交</button>
    </div>
  </div>
</template>

<script>
  import BInput from '@/components/public-modules/cust-tab-content/business/base/Binput.vue'
  import BTextarea from '@/components/public-modules/cust-tab-content/business/base/Btextarea.vue'
  import BFile from '@/components/public-modules/cust-tab-content/business/base/Bfile.vue'
  import {removeEmptyProperty} from '@/utils/m7Utils'
  import { commitImgType2 } from '@/utils/publicMethod.js'
  export default {
    name: 'businessCommon',
    data () {
      return {
        activeNames: '1',
        currentIndex: 'BusinessHelp',
        fields: ['fields1', 'fields2', 'fields3', 'fields4']
      }
    },
    props: {
      cssStyle: {type: Object, default: function () { return {row: 8, placeHolder: ''} }},
      config: {type: Object, default: function () { return {} }}
    },
    components: {
      BInput,
      BTextarea,
      BFile
    },
    methods: {
      showBigImg (data) {
        // 获取所有包含imgA的图片
        let _array = this.$el.querySelectorAll('.business-common .imgA')
        commitImgType2(data, _array)
      },
      backHome () {
        this.$emit('backHome')
      },
      resetForm () {
        for (let i = 0; i < this.fields.length; i++) {
          this.$refs[this.fields[i]].resetForm()
        }
      },
      submit () {
        let data = {}
        let pass = true
        for (let i = 0; i < this.fields.length; i++) {
          let item = this.$refs[this.fields[i]].submit()
          if (item.success && pass) {
            Object.assign(data, item.data)
          } else {
            pass = false
          }
          if (!pass) {
            return
          }
        }
        if (!Object.keys(removeEmptyProperty(data)).length) {
          this.$message.error('请填写工单内容')
          return
        }
        Object.assign(data, this.config)
        this.$store.dispatch('submitConfigBusinessFlowApply', data).then((res) => {
          if (res.success) {
            let accountConsumeLever = this.$store.state.session.account.accountConsumeLever
            if (accountConsumeLever <= 3) {
              // 中大客户
              this.$message.success('已收到您的配置申请，我们将即刻安排工作人员为您进行配置，届时请关注配置进度的通知')
            } else {
              this.$message.success('已收到您的配置申请，我们将在一个工作日内为您配置好，届时请关注配置进度的通知')
            }
            this.backHome()
          }
        })
      }
    }
  }
</script>

<style scoped lang="stylus">
  @import "../../../../assets/common.styl"
  .btn
    text-align center
    padding-top 20px
  .prompt
    color $c-prompt
</style>
